#include "FindObject.h"

#include "Framework/Application.h"
#include "NewObjectInner.h"

#include "Object/Object.h"
#include "Object/ObjectPathUtils.h"

RObjectPtr FindObject(const CString &InObjectPath)
{
    //split path 
    TVector<CString> PathParts=WH::SplitObjectPath(InObjectPath);
    assert(PathParts.size()>0);

    //find object in root
    RRootObject* Root= WH::GetRootObject();
    RObject* CurrentObject=(RObject*)Root;
    PathParts.RemoveAt(0);

    while(!PathParts.Empty())
    {
        CString CurrentPart=PathParts[0];
        PathParts.RemoveAt(0);


        //find object in current object
        RObject* FoundObject=CurrentObject->FindChild(CurrentPart);

        if(!FoundObject)
        {
            return nullptr;
        }

        CurrentObject=FoundObject;

    }

    return CurrentObject;
}
